const express = require('express')
const app = express()


// /* 获取post请求传递的参数 */
const bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())


/* 服务器解决跨域cors */
const cors = require('cors')
app.use(cors())

app.post('/login', (req, res) => {
    console.log(req.body, 4444);
    const { username } = req.body
    if (username == 'admin') {
        res.send({
            code:200,
            token:'112wswes',
            roles:[...xz,...ds]
        })
    } else if (username == 'xz') {
        res.send({
            code:200,
            token:'112wswes',
            roles:xz
        })
    } else {
        res.send({
            code:200,
            token:'112wswes',
            roles:ds
        })
    }

})

const xz = [
    {
        path: "/xz1",
        component: "xz1"
    },
    {
        path: "/xz2",
        component: "xz2"
    },
    {
        path: "/xz3",
        component: "xz3"
    },
    {
        path: "/xz4",
        component: "xz4"
    }

]

const ds = [
    {
        path: "/ds1",
        component: "ds1"
    },
    {
        path: "/ds2",
        component: "ds2"
    },
    {
        path: "/ds3",
        component: "ds3"
    }
]

app.listen(2000, () => {
    console.log('http://127.0.0.1:2000')
})